const app=getApp();
Page({
  data: {
    arrayList:[],
    name1:'',
    name2:''
  },
  linkto(e){
    var id=e.currentTarget.id;
    for(var i=0;i<this.data.arrayList.length;i++){
      if(this.data.arrayList[i].id==id){
        var obj=this.data.arrayList[i];
        console.log(obj);
        wx.setStorageSync('collectobj', obj)
        this.setData({name1:obj.name})
      }
    };
    wx.navigateTo({
      url: '/pages/collectpage/collectpage',
    })
  },
  discollect(e){
    var id=e.currentTarget.id;
    for(var i=0;i<this.data.arrayList.length;i++){
      if(this.data.arrayList[i].id==id){
        var obj=this.data.arrayList[i];
        console.log(obj);
        this.setData({name2:obj.name})
      }
    };
    wx.request({
      url:`${app.globalData.url}/user/collect/123`,
      dataType:'json',
      method:'DELETE',
      header:{
        "content-type":'application/json',
        'authorization': wx.getStorageSync('token')
      },
      data: {name: this.data.name2},
      success:res=>{
          console.log('delete collect sucess');
          this.setData({
            arrayList:res.data
            // 将获取到的数据传给初始化的变量，在后端渲染
          })
          this.getok();
      },
      fail(){
        console.log(err);
      }
    })
  },
  getok(){
    wx.request({
      url:`${app.globalData.url}/user/collect`,
      dataType:'json',
      method:'GET',
      header:{
        "content-type":'application/json',
        'authorization': wx.getStorageSync('token')
      },
      success:res=>{
        // var arr=[];
         console.log(res.data);
        //   var length=res.data.length;
        //   for(var i=0;i<length;i++){
        //     if(res.data[i].open_id)
        //   }
          this.setData({
            arrayList:res.data
            // 将获取到的数据传给初始化的变量，在后端渲染
          })
          console.log(this.data.arrayList)
      },
      fail(){
        console.log("no");
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getok();
  }
})